package com.guan.controller;

import com.alibaba.fastjson.JSON;
import com.guan.core.BaseController;
import com.guan.core.CustomView;
import com.guan.core.annotation.Autowired;
import com.guan.core.annotation.Controller;
import com.guan.core.annotation.RequestMapping;
import com.guan.core.entity.PageData;
import com.guan.core.entity.ReturnContent;
import com.guan.service.MenuService;
import com.guan.util.SystemUtil;

import java.util.List;
import java.util.Map;

/**
 * 获取左边菜单的控制类
 * Created by Administrator on 2018/1/25 0025.
 */
@Controller
@RequestMapping("/menu")
public class SysMenuController extends BaseController{
    @Autowired("menuService")
    private MenuService menuService;
    @RequestMapping("/getData")
    public CustomView getMenuData(){
        PageData pd = this.getPageDate();
        String userId = pd.getString("userId");
        String bathPath = SystemUtil.getBasePath(this.getReq());
        List<Map<String,Object>> menulist = menuService.getMenuData(userId,bathPath);
        ReturnContent rc = new ReturnContent(menulist);
        CustomView cv = new CustomView(rc);
        return cv;
    }
    @RequestMapping("/list")
    public CustomView getMenuList(){
        PageData pd = this.getPageDate();
        String userId = pd.getString("userId");
        List<Map<String,Object>> menulist = menuService.getMenuData(userId);
        String menulistStr="";
        if(menulist!=null&&menulist.size()>0){
            menulistStr= JSON.toJSONString(menulist);
        }
        put("menulist",menulistStr);
        CustomView cv =  new CustomView("menu/menuIndex");
        return cv;
    }
}
